<?php
/*******************************************************************************
 * $Date:: Jan 10, 2011 9:42:38 PM                                             $
 * $Revision:                                                                  $
 * $Author:: Tuan Duong                                                        $
 * $Comment::                                                                  $
 ******************************************************************************/ 
/**
 * Description here...
 * 
 * @package Lua
 * @subpackage ##Subpackage##
 * @author Tuan Duong <bacduong[at]gmail[dot]com>
 * @version 
 */

class Lua_Auth_User implements Zend_Auth_Adapter_Interface
{
    /**
     * @var string
     */
    protected $username;
    /**
     * @var string
     */
    protected $password;
    
    /**
     * Construtor for Lua_Auth_User
     * @param string $username
     * @param string $password
     */
    public function __construct($username, $password)
    {
        $this->username = $username;
        $this->password = $password;
    }

    public function authenticate()
    {
        $baseService = Lua_Service_Locator::getBaseService();
        $userBean = $baseService->findRow(Lua_Constant_Database::TBL_USER, array('username = ?' => $this->username));
        if (!$userBean->isEmpty()) {
            $cryptedPassword = Lua_Crypt::factory()->encrypt($this->password);
            if ($cryptedPassword == $userBean->password) {
//                $identity = new stdClass();
//                $identity->username = $userBean->username;
//                $identity->email = $userBean->email;
//                $identity->id = $userBean->id;
//                $identity->full_name = $
                return new Zend_Auth_Result(Zend_Auth_Result::SUCCESS, $userBean, array());                                
            }
        }
        return new Zend_Auth_Result(Zend_Auth_Result::FAILURE, $this->username);
    }
}